﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using NPOI.POIFS.Crypt.Dsig;
namespace RDBill
{
    public partial class RDBill : Form
    {
        public RDBill()
        {
            InitializeComponent();
        }
        DataTable dataTable = new DataTable();
        private void brnimport_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "EXCEL文件(*.xlsx)|*.xlsx|EXCEL文件(*.xls)|*.xls";
           DialogResult dialogResult= openFileDialog.ShowDialog();
            if (dialogResult == DialogResult.OK) { 
                string filename= openFileDialog.FileName;
                ExcelHelper excelHelper = new ExcelHelper(filename);
                string sheetname = ConfigurationManager.AppSettings["sheetname"];
               
                dataTable = excelHelper.ExcelToDataTable(sheetname, true);
            
                dgvData.DataSource = dataTable;
            }
        }

        private DataTable CreateTable()
        {
            DataTable table = new DataTable();
            table.Columns.Add("RDitem", typeof(string));
            table.Columns.Add("WLID", typeof(string));
            table.Columns.Add("DepotDate", typeof(DateTime));
            table.Columns.Add("Price", typeof(decimal));
            table.Columns.Add("CountAmount", typeof(decimal));
            table.Columns.Add("CountPrice", typeof(decimal));
            return table;
        }
        private string GetnoticeCode(int BillCode)
        {
            string sql=string.Empty;
            DataTable CodeTable = new DataTable();
            if (BillCode == 0)
            {
                sql = "select SUBSTRING(max(QTRKTZD_TZDID), 1,2) as QZ, SUBSTRING(max(QTRKTZD_TZDID), 3,4) AS NY, SUBSTRING(max(QTRKTZD_TZDID), 7,4) AS XH from QTRKTZD";
                CodeTable= new DBHelper().GetDataTable(sql);
            }
            else
            {
                sql = "select SUBSTRING(max(WOLL_LLDID), 1,2) as QZ, SUBSTRING(max(WOLL_LLDID), 3,4) AS NY, SUBSTRING(max(WOLL_LLDID), 7,4) AS XH from WOLL WHERE WOLL_LLDID like '%LE%'";
                CodeTable=new DBHelper().GetDataTable(sql);
            
            }
            
            string NY=DateTime.Now.Year.ToString().Substring(2,2)+ DateTime.Now.ToString("MM");
            string Code=string.Empty;
            if (NY.Equals(CodeTable.Rows[0]["NY"]))
            {
                Code = CodeTable.Rows[0]["QZ"].ToString() + CodeTable.Rows[0]["NY"] + GetFormatCode(long.Parse(CodeTable.Rows[0]["XH"].ToString()) + 1,"0");
            }
            else
            {
                Code = CodeTable.Rows[0]["QZ"].ToString() + NY + "0001";
            }

            return Code;

        }
        private string GetFormatCode(long Code,string notice)
        {
            string NextCode = string.Empty;
            if (notice.Equals("0"))
            {
                switch (Code.ToString().Length)
                {
                    case 1:
                        NextCode = "000" + Code.ToString();
                        break;
                    case 2:
                        NextCode = "00" + Code.ToString();
                        break;
                    case 3:
                        NextCode = "0" + Code.ToString();
                        break;
                    case 4:
                        NextCode = Code.ToString();
                        break;
                    default:
                        break;
                }
            }
            else {
                switch (Code.ToString().Length)
                {
                    case 1:
                        NextCode = "00" + Code.ToString();
                        break;
                    case 2:
                        NextCode = "0" + Code.ToString();
                        break;
                    case 3:
                        NextCode =  Code.ToString();
                        break;
                    default:
                        break;
                }
            }
                return NextCode;
        }
        private string GetNextCode(string Code)
        {
            string NextCode=string.Empty;
            string XH = Code.Substring(6);
            long next=long.Parse(XH)+1;

            NextCode = GetFormatCode(next, "0");
            NextCode = Code.Substring(0, 6) + NextCode;
            return NextCode;
        }
        private string GetDepotNextCode(string Code)
        {
            string NextCode = string.Empty;
            string XH = Code.Substring(7);
            long next = long.Parse(XH) + 1;

            NextCode = GetFormatCode(next,"1");
            NextCode = Code.Substring(0, 7) + NextCode;
            return NextCode;
        }
        private string GetDepotCode(string TZM)
        {
            //1.获取前缀
            string sql = "select MISPRONAME_QZ from MisproName where MISPRONAME_TZM='"+ TZM + "'";
            string QZ= new DBHelper().GetDataTable(sql).Rows[0][0].ToString().Trim();
            string NY = DateTime.Now.Year.ToString().Substring(2, 2) + DateTime.Now.ToString("MM");
            string Code = string.Empty;
            sql = "select SUBSTRING(max(KCSWZ_SWKCBH), 1,3) as QZ, SUBSTRING(max(KCSWZ_SWKCBH), 4,4) AS NY, SUBSTRING(max(KCSWZ_SWKCBH), 8,4) AS XH from KCSWZ where KCSWZ_CKID='"+ ConfigurationManager.AppSettings["CKID"] + "' AND KCSWZ_BMID='"+ ConfigurationManager.AppSettings["BMID"] + "' and KCSWZ_SWKCBH like '%"+ QZ + "%'";
            DataTable CodeTable = new DBHelper().GetDataTable(sql);
            if (CodeTable.Rows.Count <= 0)
            {
                Code = QZ + NY + "0001";
            }
            else {
                if (NY.Equals(CodeTable.Rows[0]["NY"]))
                {
                    Code = QZ + CodeTable.Rows[0]["NY"] + GetFormatCode(long.Parse(CodeTable.Rows[0]["XH"].ToString()) + 1, "1");
                }
                else
                {
                    Code = QZ + NY + "001";
                }
            }
            return Code;
        }
        private void btnInDepot_Click(object sender, EventArgs e)
        {
            //1.对记录进行分组处理

            //1.1.创建新的DataTable
            DataTable data = CreateTable();
            var query = from row in dataTable.AsEnumerable()
                        group row by new
                        {
                            RDitem = row.Field<string>("RD项目"),
                            DepotDate = row.Field<string>("入库日期"),
                            WLID = row.Field<string>("物料编码"),
                            Price =decimal.Parse(row.Field<string>("单价")),
                        } into grp
                        select new
                        {
                            grp.Key.RDitem,
                            grp.Key.WLID,
                            grp.Key.DepotDate,
                            grp.Key.Price,
                            CountAmount = grp.Sum(r =>decimal.Parse(r.Field<string>("数量"))),
                            CountPrice = grp.Sum(r => decimal.Parse(r.Field<string>("总金额")))
                        };
            foreach (var item in query)
            {
                DataRow newRow = data.NewRow();
                newRow["RDitem"] = item.RDitem;
                newRow["WLID"] = item.WLID;
                newRow["DepotDate"] = item.DepotDate;
                newRow["Price"] = item.Price;
                newRow["CountAmount"] = item.CountAmount;
                newRow["CountPrice"] = item.CountPrice;
                data.Rows.Add(newRow);
            }
            DataView dataView = data.DefaultView;
            dataView.Sort = "RDitem,DepotDate";
            DataTable DataBill = dataView.ToTable(true, new string[] { "RDitem", "DepotDate" });
            List<string> listsql=new List<string> ();
            string BillCode = GetnoticeCode(0);
            string DepotCode=GetDepotCode("KC_KCBH"+ ConfigurationManager.AppSettings["CKID"] + "R");
            listsql = GetPHSXList(listsql, data);
            foreach (DataRow itemRow in DataBill.Rows)
            {
                DataView dvInfo = data.DefaultView;
                dvInfo.RowFilter = "RDitem='" + itemRow["RDitem"] + "' and DepotDate='" + itemRow["DepotDate"] + "'";
                DateTime dateTimeInfo = DateTime.Parse(itemRow["DepotDate"].ToString());
                //插入主表
                //1.1其他入库单

                string sql = "insert into QTRKTZD(QTRKTZD_TZDID, QTRKTZD_SWLX, QTRKTZD_KDRQ, QTRKTZD_CKID, QTRKTZD_BMID,  QTRKTZD_JSRGH, QTRKTZD_JSR, QTRKTZD_SJRQ, QTRKTZD_KHID, QTRKTZD_GYSID,  QTRKTZD_BZ, QTRKTZD_PZBZ, QTRKTZD_PZR, QTRKTZD_PZRQ, QTRKTZD_WFID, QTRKTZD_WFINST,  QTRKTZD_WPID, QTRKTZD_WFAWAITER, QTRKTZD_WFHANDLER, QTRKTZD_WHRID, QTRKTZD_WHR, QTRKTZD_WHSJ, QTRKTZD_SFTK, QTRKTZD_DOCGRPID, QTRKTZD_FJS)" +
                    "values ('"+BillCode+"','"+ ConfigurationManager.AppSettings["TLSW"] + "','"+dateTimeInfo.ToString("yyyy-MM-dd")+"','"+ ConfigurationManager.AppSettings["CKID"] + "','"+ ConfigurationManager.AppSettings["BMID"] + "','SUPERVISOR','超级用户',NULL,NULL,NULL,'生产退料','Y',' ',NULL,' ',0,'ZZZZ',NULL,NULL,'SUPERVISOR','超级用户','"+dateTimeInfo+"','N',0,0)"; 
                listsql.Add (sql);
                sql = "insert into KCSWZ(KCSWZ_SWKCBH,KCSWZ_CKID,KCSWZ_SWLX,KCSWZ_RCKDH,KCSWZ_JZRQ,KCSWZ_DFCK,KCSWZ_KHID,KCSWZ_GYSID,KCSWZ_BMID,KCSWZ_ZY,KCSWZ_YEAR,KCSWZ_MONTH,KCSWZ_ZPZH,KCSWZ_YSR,KCSWZ_JSRID,KCSWZ_JSR,KCSWZ_SCBZ,KCSWZ_SHR,KCSWZ_YKCBH,KCSWZ_SHRQ,KCSWZ_GHFPID,KCSWZ_SFTK,KCSWZ_NW,KCSWZ_JSFS,KCSWZ_WHR,KCSWZ_WHSJ,KCSWZ_WHRID,KCSWZ_KZFS,KCSWZ_FPGYSID)" +
                    "values('"+DepotCode+"','"+ ConfigurationManager.AppSettings["CKID"] + "','" + ConfigurationManager.AppSettings["TLSW"] + "','"+BillCode+"','"+dateTimeInfo.ToString("yyyy-MM-dd")+"',' ','','','" + ConfigurationManager.AppSettings["BMID"] + "','生产退料',"+ dateTimeInfo.Year + ","+ dateTimeInfo .Month+ ",0,'超级用户','SUPERVISOR','超级用户','Y',' ',' ',NULL,' ','N',' ',' ','超级用户','"+ dateTimeInfo + "','SUPERVISOR',' ',' ')";
                listsql.Add(sql);
                sql = "update QTRKTZD set QTRKTZD_SJRQ='" + itemRow["DepotDate"] + "'" +
                    "where QTRKTZD_TZDID='" + BillCode + "' and (DATEPART(year,QTRKTZD_WHSJ)=DATEPART(year,'" + itemRow["DepotDate"] + "')) AND (DATEPART(month,QTRKTZD_WHSJ)=DATEPART(month,'" + itemRow["DepotDate"] + "')) AND (DATEPART(day,QTRKTZD_WHSJ)=DATEPART(day,'" + itemRow["DepotDate"] + "')) ";
                  
                listsql.Add(sql);
                int i = 1;
                foreach (DataRowView itemview in dvInfo)
                {
                    decimal absa =Math.Round(decimal.Parse(itemview["CountAmount"].ToString()) * 1,4);
                    decimal CountPrice = Math.Round(absa * decimal.Parse(itemview["Price"].ToString()),2);
                    //插入从表
                    string sqlitem = "insert into QTRKTZDMX (QTRKTZDMX_TZDID, QTRKTZDMX_TZDXH, QTRKTZDMX_WLID, QTRKTZDMX_YSSL, QTRKTZDMX_WSJG,  QTRKTZDMX_WSJE, QTRKTZDMX_SSSL, QTRKTZDMX_YRK, QTRKTZDMX_SWLX, QTRKTZDMX_WLPH,   QTRKTZDMX_BZ, QTRKTZDMX_ZLH, QTRKTZDMX_FZYSSL, QTRKTZDMX_FZSSSL, QTRKTZDMX_PJWLID,   QTRKTZDMX_PJTZDID, QTRKTZDMX_PJRKSL) values" +
                        " ('"+BillCode+"',"+i+ ",'"+ itemview["WLID"] + "',"+ absa + ","+ itemview["Price"] + ","+ CountPrice + ",0,'N','" + ConfigurationManager.AppSettings["TLSW"] + "','"+ itemview["RDitem"] + "','生产退料','',0,0,NULL,'',0)";
                    listsql.Add(sqlitem);
                    listsql.Add("update QTRKTZDMX set QTRKTZDMX_TZDXH=abs(QTRKTZDMX_TZDXH) where QTRKTZDMX_TZDID='" + BillCode + "' and QTRKTZDMX_TZDXH<0");
                  
                    sqlitem = "insert into KCSWZMX(KCSWZMX_SWKCBH,KCSWZMX_XH,KCSWZMX_WLID,KCSWZMX_RKRQ,KCSWZMX_RKSL,KCSWZMX_FZRKSL,KCSWZMX_CKSL,KCSWZMX_FZCKSL,KCSWZMX_SJCKJE,KCSWZMX_BZCKJE,KCSWZMX_FYJE,KCSWZMX_KW,KCSWZMX_WLPH,KCSWZMX_BZ,KCSWZMX_JCJS,KCSWZMX_DDXH,KCSWZMX_GYSID,KCSWZMX_KHID,KCSWZMX_SCRQ,KCSWZMX_XGDDID,KCSWZMX_XGDDXH,KCSWZMX_WHR,KCSWZMX_WHSJ,KCSWZMX_WHRID,KCSWZMX_ZLH,KCSWZMX_KJXMID,KCSWZMX_CKID,KCSWZMX_SWLX,KCSWZMX_FWLID,KCSWZMX_YSFSL,KCSWZMX_KCKMID,KCSWZMX_CYKMID,KCSWZMX_DFKMID,KCSWZMX_JHZCKM,KCSWZMX_DFKMID2,KCSWZMX_JZRQ,KCSWZMX_YEAR,KCSWZMX_MONTH)" +
                        "values('"+DepotCode+"',"+i*1000+",'"+ itemview["WLID"] + "','"+ dateTimeInfo.ToString("yyyy-MM-dd") + "',"+absa+",0,0,0,0,0,0,'','"+ itemview["RDitem"] + "','生产退料',' ',"+i+",'','',NULL,' ',0,'超级用户','"+dateTimeInfo+"','SUPERVISOR','',' ','" + ConfigurationManager.AppSettings["CKID"] + "','" + ConfigurationManager.AppSettings["TLSW"] + "',' ',0,' ',' ',' ',' ',' ','"+ dateTimeInfo.ToString("yyyy-MM-dd") + "',"+ dateTimeInfo .Year+ ","+dateTimeInfo.Month+")";
                    listsql.Add(sqlitem);
                    sqlitem = "update QTRKTZDMX set QTRKTZDMX_SSSL=" + absa + ",QTRKTZDMX_FZSSSL=0,QTRKTZDMX_SJWLPH='" + itemview["RDitem"] + "',QTRKTZDMX_YRK='Y'  where QTRKTZDMX_TZDID='" + BillCode + "' and QTRKTZDMX_TZDXH='"+i.ToString()+"'";
                    listsql.Add(sqlitem);
                    i=i+1;
                }
                //sql = "exec JSERP8.JLKCSLJEZ 100502023,'"+ ConfigurationManager.AppSettings["CKID"] + "','"+ BillCode + "','I','超级用户','SUPERVISOR','N'";
                //listsql.Add(sql);
                BillCode = GetNextCode(BillCode);
                DepotCode= GetDepotNextCode(DepotCode);
            }
            int result = new DBHelper().ExecuteInt(listsql);
            if (result >= 0)
            {
                MessageBox.Show("ok");
            }
            else {
                MessageBox.Show("nook");
            }
      
        }
        private List<string> GetPHSXList(List<string> strings,DataTable dataTable) {
            DataView dv = dataTable.DefaultView;
            dv.Sort = "RDitem,WLID";
            DataTable DataBill = dv.ToTable(true, new string[] { "RDitem", "WLID" });
            foreach (DataRow dr in DataBill.Rows) {
                string sqlitem = "delete from PHSX where PHSX_WLID='" + dr["WLID"].ToString().Trim() + "' and PHSX_WLPH='" + dr["RDitem"].ToString().Trim() + "'";
                strings.Add(sqlitem);
                sqlitem ="insert into PHSX(PHSX_SXXX,PHSX_SXSZ01,PHSX_SXZF29,PHSX_WLID,PHSX_WLPH)values(NULL,0,NULL,'" + dr["WLID"].ToString().Trim() + "','" + dr["RDitem"].ToString().Trim() + "')";

                strings.Add(sqlitem);
            }
            return strings;
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
            //1.对记录进行分组处理

            //1.1.创建新的DataTable
            DataTable data = CreateTable();
            var query = from row in dataTable.AsEnumerable()
                        group row by new
                        {
                            RDitem = row.Field<string>("RD项目"),
                            DepotDate = row.Field<string>("出库日期"),
                            WLID = row.Field<string>("物料编码"),
                            Price = decimal.Parse(row.Field<string>("单价")),
                        } into grp
                        select new
                        {
                            grp.Key.RDitem,
                            grp.Key.WLID,
                            grp.Key.DepotDate,
                            grp.Key.Price,
                            CountAmount = grp.Sum(r => decimal.Parse(r.Field<string>("数量"))),
                            CountPrice = grp.Sum(r => decimal.Parse(r.Field<string>("总金额")))
                        };
            foreach (var item in query)
            {
                DataRow newRow = data.NewRow();
                newRow["RDitem"] = item.RDitem;
                newRow["WLID"] = item.WLID;
                newRow["DepotDate"] = item.DepotDate;
                newRow["Price"] = item.Price;
                newRow["CountAmount"] = item.CountAmount;
                newRow["CountPrice"] = item.CountPrice;
                data.Rows.Add(newRow);
            }
            DataView dataView = data.DefaultView;
            dataView.Sort = "RDitem,DepotDate";
            DataTable DataBill = dataView.ToTable(true, new string[] { "RDitem", "DepotDate" });
            List<string> listsql = new List<string>();
            string BillCode = GetnoticeCode(1);
            string DepotCode = GetDepotCode("KC_KCBH" + ConfigurationManager.AppSettings["CKID"] + "C");
            listsql = GetPHSXList(listsql, data);
            foreach (DataRow itemRow in DataBill.Rows)
            {
                DataView dvInfo = data.DefaultView;
                dvInfo.RowFilter = "RDitem='" + itemRow["RDitem"] + "' and DepotDate='" + itemRow["DepotDate"] + "'";
                DateTime dateTimeInfo = DateTime.Parse(itemRow["DepotDate"].ToString());
                //插入主表
                //1.1非定额领料单
                string sql = string.Empty;
                sql = "insert into WOLL (WOLL_LLDID, WOLL_BMID, WOLL_CKID, WOLL_PZBZ, WOLL_PZR, WOLL_PZRQ, WOLL_JHBZ,   WOLL_BZBH, WOLL_SFTK, WOLL_WHRID, WOLL_WHR, WOLL_WHSJ, WOLL_LLRQ, WOLL_GCID,   WOLL_SWLX, WOLL_LLRID, WOLL_LLR, WOLL_WFID, WOLL_WFINST, WOLL_YLLDID,   WOLL_BZ, WOLL_WPID, WOLL_SCFS, WOLL_SCSBID,WOLL_FJS,WOLL_DOCGRPID,WOLL_BC)" +
                    "values ('" + BillCode + "','" + ConfigurationManager.AppSettings["BMID"] + "','" + ConfigurationManager.AppSettings["CKID"] + "','Y',NULL,NULL,'L','','N','SUPERVISOR','超级用户','" + itemRow["DepotDate"] + "','" + itemRow["DepotDate"] + "','01','" + ConfigurationManager.AppSettings["LLSW"] + "',NULL,NULL,NULL,0,'','研发领用','ZZZZ','Z','',0,0,NULL)";

                listsql.Add(sql);

                sql = "update WOLL set WOLL_SJRQ='" + itemRow["DepotDate"].ToString() + "'" +
                    "where WOLL_LLDID='" + BillCode + "' and (DATEPART(year,WOLL_WHSJ)=DATEPART(year,'" + itemRow["DepotDate"] + "')) AND (DATEPART(month,WOLL_WHSJ)=DATEPART(month,'" + itemRow["DepotDate"] + "')) AND (DATEPART(day,WOLL_WHSJ)=DATEPART(day,'" + itemRow["DepotDate"] + "'))";

                listsql.Add(sql);
                sql = "insert into KCSWZ(KCSWZ_SWKCBH,KCSWZ_CKID,KCSWZ_SWLX,KCSWZ_RCKDH,KCSWZ_JZRQ,KCSWZ_DFCK,KCSWZ_KHID,KCSWZ_GYSID,KCSWZ_BMID,KCSWZ_ZY,KCSWZ_YEAR,KCSWZ_MONTH,KCSWZ_ZPZH,KCSWZ_YSR,KCSWZ_JSR,KCSWZ_SCBZ,KCSWZ_SHR,KCSWZ_YKCBH,KCSWZ_SHRQ,KCSWZ_GHFPID,KCSWZ_SFTK,KCSWZ_NW,KCSWZ_JSFS,KCSWZ_WHR,KCSWZ_WHSJ,KCSWZ_WHRID,KCSWZ_KZFS,KCSWZ_FPGYSID,KCSWZ_JSRID) values" +
                    "('" + DepotCode + "','" + ConfigurationManager.AppSettings["CKID"] + "','" + ConfigurationManager.AppSettings["LLSW"] + "','" + BillCode + "','" + itemRow["DepotDate"] + "',' ',' ',' ','" + ConfigurationManager.AppSettings["BMID"] + "','领料出库:" + BillCode + "'," + dateTimeInfo.Year + "," + dateTimeInfo.Month + ",0,'超级用户','','Y','',' ',NULL,' ','N',' ',' ','超级用户','" + itemRow["DepotDate"] + "','SUPERVISOR','','','')";
                listsql.Add(sql);
                int i = 1;
          
                foreach (DataRowView itemview in dvInfo)
                {
                    decimal absa = Math.Round(decimal.Parse(itemview["CountAmount"].ToString()), 4);
                    //  decimal CountPrice = Math.Round(absa * decimal.Parse(itemview["Price"].ToString()), 2);
                    //插入从表
                    string sqlitem = string.Empty;
                    sqlitem = "insert into WOLLMX (WOLLMX_LLDID, WOLLMX_XH, WOLLMX_WOID, WOLLMX_ZLH, WOLLMX_FWLID,   WOLLMX_BOMXH, WOLLMX_WLID, WOLLMX_WLPH, WOLLMX_YFSL, WOLLMX_YFL,   WOLLMX_FPH, WOLLMX_BZ, WOLLMX_JHBZ, WOLLMX_SFTK, WOLLMX_CKID,   WOLLMX_SWLX, WOLLMX_KBID, WOLLMX_KBXH, WOLLMX_FZYFSL,WOLLMX_ZT, WOLLMX_SCSL, WOLLMX_JHXH, WOLLMX_GXID,   WOLLMX_BZGXID, WOLLMX_PZBZ, WOLLMX_SCFS, WOLLMX_JHID) values" +
                        " ('" + BillCode + "'," + i + ",'',' ',' ',0,'" + itemview["WLID"] + "','" + itemview["RDitem"] + "'," + absa + ",'N',0,NULL,'L','N','" + ConfigurationManager.AppSettings["CKID"] + "','" + ConfigurationManager.AppSettings["LLSW"] + "',NULL,0,0,'I',0,0,0,NULL,'Y','Z',NULL)";
                    listsql.Add(sqlitem);
                    sqlitem = "update WOLLMX set WOLLMX_YFL='Y',WOLLMX_SJWLPH='" + itemview["RDitem"] + "',WOLLMX_SFSL=" + absa + ",WOLLMX_FZSFSL=0,WOLLMX_ZT='C' where WOLLMX_LLDID='" + BillCode + "' and WOLLMX_XH=" + i;
                    listsql.Add(sqlitem);
                    sqlitem = "insert into KCSWZMX(KCSWZMX_SWKCBH,KCSWZMX_XH,KCSWZMX_WLID,KCSWZMX_RKRQ,KCSWZMX_RKSL,KCSWZMX_FZRKSL,KCSWZMX_CKSL,KCSWZMX_FZCKSL,KCSWZMX_FYJE,KCSWZMX_KW,KCSWZMX_WLPH,KCSWZMX_BZ,KCSWZMX_JCJS,KCSWZMX_DDXH,KCSWZMX_GYSID,KCSWZMX_KHID,KCSWZMX_SCRQ,KCSWZMX_XGDDID,KCSWZMX_XGDDXH,KCSWZMX_WHR,KCSWZMX_WHSJ,KCSWZMX_WHRID,KCSWZMX_ZLH,KCSWZMX_KJXMID,KCSWZMX_CKID,KCSWZMX_SWLX,KCSWZMX_FWLID,KCSWZMX_YSFSL,KCSWZMX_JZRQ,KCSWZMX_YEAR,KCSWZMX_MONTH) " +
                        "values('" + DepotCode + "'," + (i * 1000 + 1) + ",'" + itemview["WLID"] + "',NULL,0,0," + absa + ",0,0,'','" + itemview["RDitem"] + "','领料出库:" + BillCode + "/" + i + "','N'," + i + ",'','',NULL,'',0,'超级用户','" + itemRow["DepotDate"] + "','SUPERVISOR','','','" + ConfigurationManager.AppSettings["CKID"] + "','" + ConfigurationManager.AppSettings["LLSW"] + "','',0,'" + itemRow["DepotDate"] + "'," + dateTimeInfo.Year + "," + dateTimeInfo.Month + ")";
                    listsql.Add(sqlitem);
                    i = i + 1;
                }
                BillCode = GetNextCode(BillCode);
                DepotCode = GetDepotNextCode(DepotCode);
            }
             int result = new DBHelper().ExecuteInt(listsql);
            if (result >= 0)
            {
                MessageBox.Show("ok");
            }
            else
            {
                MessageBox.Show("nook");
            }
            
        }
    }
}
